<?php
namespace App\Http\Controllers;

use App\Base\AdminBase;
use App\Http\Controllers\Controller;
use App\Service\DataReturnService as DRS;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ExportController extends Controller {
	/**
	 * [commenExport 导出评论]
	 * @Author:  刘家腾
	 * @DateTime 2019-05-08
	 * @param    Request    $request [description]
	 * @return   [type]              [description]
	 */
	public function commenExport(Request $request) {

		$postData = $request->post();
		$commentData = AdminBase::activityBase($postData);
		if (empty($commentData)) {
			return DRS::returnOk($reData, '暂无相关数据');
		}

		foreach ($commentData['data'] as $key => $value) {
			$commentData['data'][$key] = json_decode(json_encode($value), true);
			if ($commentData['data'][$key]['is_shield'] == 1) {
				$commentData['data'][$key]['is_shield_masge'] = '屏蔽';
			} else {
				$commentData['data'][$key]['is_shield_masge'] = '取消屏蔽';
			}
		}

		$activityTypeData = AdminBase::activity_typeBase();
		$commentData['activity_title'] = $activityTypeData;

		$Column = ['id', 'user_name', 'content', 'activity_title', 'createtime', 'avtivity_type_title'];
		$titleList = ['ID', '用户昵称', '评论内容', '名称', '评论时间', '评论类型'];
		$fileName = '活动评论数据-' . date("Y-m-d");

		$commentData['excel']['Column'] = $Column;
		$commentData['excel']['titleList'] = $titleList;
		$commentData['excel']['fileName'] = $fileName;

		return DRS::returnOk($commentData);

	}
	/**
	 * [feedbackExport 导出意见反馈]
	 * @Author:  刘家腾
	 * @DateTime 2019-05-08
	 * @param    Request    $request [description]
	 * @return   [type]              [description]
	 */
	public function feedbackExport(Request $request) {
		$postData = $request->post();
		$feedbackData = AdminBase::getFeedbackSql($request);

		foreach ($feedbackData['data'] as $key => $value) {
			$feedbackData['data'][$key] = json_decode(json_encode($value), true);
			if ($feedbackData['data'][$key]['condition'] == 1) {
				$feedbackData['data'][$key]['condition'] = '未处理';
			} else {
				$feedbackData['data'][$key]['condition'] = '已处理';
			}
		}

		$Column = ['id', 'user_name', 'mobile', 'comment', 'createtime', 'condition'];
		$titleList = ['ID', '用户昵称', '手机号', '反馈内容', '反馈时间', '状态'];
		$fileName = '意见反馈数据-' . date("Y-m-d");

		$feedbackData['excel']['Column'] = $Column;
		$feedbackData['excel']['titleList'] = $titleList;
		$feedbackData['excel']['fileName'] = $fileName;

		return DRS::returnOk($feedbackData);

	}
	/**
	 * [calendarExport 日历导出]
	 * @Author      yuejie89@sina.cn
	 * @DateTime    2019-05-29
	 * @description []
	 * @param       Request          $request [description]
	 * @return      [type]                    [description]
	 */
	public function calendarExport(Request $request) {
		$postData = $request->post();
		$resData = AdminBase::getCalendarListSql($request);

		foreach ($resData['data'] as $key => $value) {
			$resData['data'][$key] = json_decode(json_encode($value), true);
			if ($resData['data'][$key]['condition'] == 1) {
				$resData['data'][$key]['condition'] = '草稿';
			} else if ($resData['data'][$key]['condition'] == 2) {
				$resData['data'][$key]['condition'] = '已上架';
			} else if ($resData['data'][$key]['condition'] == 3) {
				$resData['data'][$key]['condition'] = '已下架';
			}
		}

		$Column = ['id', 'event_name', 'start_time', 'end_time', 'country', 'city', 'condition'];
		$titleList = ['ID', '赛事名称', '开始时间', '结束时间', '国家', '城市', '状态'];
		$fileName = '日历列表-' . date("Y-m-d");

		$resData['excel']['Column'] = $Column;
		$resData['excel']['titleList'] = $titleList;
		$resData['excel']['fileName'] = $fileName;

		return DRS::returnOk($resData);

	}
}
// 因只能导出单表  暂时放弃 （后期研究模型管理导出再考虑启用）
// public function export()
// {
//  // $oUser = CAcUser::with( 'hasOneExt' )->find( $sUMId );
//     return Excel::download(new CommentExport(), 'Comment.xlsx');
//     // return new UsersExport();
//     // new CommentExport();
//     // $data = new CommentExport();
//     // return $data->hasMany(); //一对多，最多关联2条
// }
